/**
 * Created by Administrator on 2017/5/27.
 * @description 登录拦截，未登录提示登录操作
 */
import jsbridge from 'utils/jsbridge';

let isLogin = function(author) {
    return new Promise((resolve, reject) => {
        try {
            jsbridge.getUserInfo(user => {
                user = user || null;
                if(author && !user) {
                    console.log('跳转登录activity界面');
                    jsbridge.jumpLoginActivity(user => {
                        if(user){
                            console.log('用户登录成功');
                            resolve(user);
                        }else {
                            console.log('登录失败...');
                            reject('用户信息为空');
                        }
                    });
                } else {
                    console.log('从原生获取用户信息...');
                    resolve(user);
                }
            });
        } catch(e) {
            reject(e);
        }
    });
};

exports.isLogin=isLogin;